package com.demo.weather;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.CommandLineRunner;
import org.springframework.stereotype.Component;

import com.demo.weather.server.WeatherServer;

@Component
public class WeatherServerRunner implements CommandLineRunner {

	private @Autowired List<WeatherServer> weatherServers;
	
	@Override
    public void run(String... args) throws Exception {
		weatherServers.stream().forEach(s->s.run());
    	
    	Runtime.getRuntime().addShutdownHook(new Thread(() -> weatherServers.stream().forEach(s->s.shutdown())));
    }
}